package com.java110.api.listener.fee;

import com.alibaba.fastjson.JSONObject;
import com.java110.api.listener.AbstractServiceApiPlusListener;
import com.java110.core.annotation.Java110Listener;
import com.java110.core.context.DataFlowContext;
import com.java110.core.event.service.api.ServiceDataFlowEvent;
import com.java110.intf.fee.IFeeInnerServiceSMO;
import com.java110.utils.constant.lm.service.code.WeEnum;
import com.java110.utils.id.GeneratorUnionID;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

@Java110Listener("weTopUpCancelListener")
public class WeTopUpCancelListener extends AbstractServiceApiPlusListener {

    @Autowired
    private IFeeInnerServiceSMO feeInnerServiceSMOImpl;

    @Override
    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {

    }

    @Override
    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
        String feeId = reqJson.getString("feeId");
        int i = feeInnerServiceSMOImpl.deleteFee(feeId);
        ResultVo vo = new ResultVo();
        if(i == 1){
            vo.setCode(0);
            vo.setMsg("ok");
        } else {
            vo.setCode(504);
            vo.setMsg("sql error");
        }
        ResponseEntity<String> responseEntity = new ResponseEntity(vo.toString(), HttpStatus.OK);
        context.setResponseEntity(responseEntity);

    }

    @Override
    public String getServiceCode() {
        return WeEnum.we_top_up_cancel.getCode();
    }

    @Override
    public HttpMethod getHttpMethod() {
        return HttpMethod.POST;
    }
}
